<%--
 *  File:    SysDictionary.jsp
 *  @Author: Kent Zhong
 *  Date:    2002/05/07
 *
 *  Copyright (C) 2000 - 2002 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.SysDictionary");
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String strModuleName = "DMS";
  	String strTableName = "jpovdictionary";
	String privilegeCode = "SFE010101";
	String contextPath = request.getContextPath();
  	//get current userinfo
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  	cat.debug("The userinfo is :"+CurUserInfo);
  	cat.info("enter my page");
%>

<% //--------------------------------------  include files list --%>

<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<%int LangNums = ConstantProp.multiLangNumber;%>

<html>
<head>
<title>SysDictionary</title>
<PageFlow:CheckPageFlow pageName="sysdictionarysummary1"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/SummaryDivision.js"></script>
<script type="text/javascript" src="<%=contextPath %>/js/opal2/mootools.js"></script>
<%
	String flag = (String)pageContext.getAttribute("flag");
%>
<%@ include file="/inc/SummaryDivision.inc" %>
<script language="JavaScript" >

    function page_typechange()
    {
      page_summary("search");
    }

    function page_add()
    {
		if (!checkForm(document.sysdictionarysummaryform)) return;
		<%if(!"1".equals(flag)){%>
		var source = eval("sysdictionarysummaryform.type");
		syncChange(source, "type", 0, <%=LangNums%>);
		<%}%>
	    sysdictionarysummaryform.actionname.value = "add";
	    sysdictionarysummaryform.target = "_self";
	    isRunning = true;
	    sysdictionarysummaryform.submit();
    }
  function page_save()
  {
    sysdictionarysummaryform.actionname.value = "save";
    sysdictionarysummaryform.target = "_self";
    isRunning = true;
    sysdictionarysummaryform.submit();
  }


  function add_newdictionarytype()
  {
  
  	var value = sysdictionarysummaryform.newtypename.value;
  	var description = sysdictionarysummaryform.newdescription.value;
  	var reg = /^[a-zA-Z]+$/ ;
    var flag = reg.test(value); 
    if(flag){
    	sysdictionarysummaryform.actionname.value = "addnewtype";
  	    sysdictionarysummaryform.target = "_self";
  	    sysdictionarysummaryform.dictionarytype.value = value;
  	    isRunning = true;
        sysdictionarysummaryform.submit();
  	    
    }else{
    	alert("该输入框只能输入字母");
    	return;
    }
    if (description==""||description==null||description==" "){
       alert("请输入类型描述");
    	return;
    }
  }

  function page_delete()
  {
    if(isNullChecked(sysdictionarysummaryform.dictionarys))
    {
      alert('<%=message.getMessageDesc("PLEASE_SELECT")%>');
      return;
    }
    sysdictionarysummaryform.actionname.value = "delete";
    sysdictionarysummaryform.target = "_self";
    isRunning = true;
    sysdictionarysummaryform.submit();
  }

  function page_summary(actionvalue,orderbyname)
	{
	  var editform = summaryPrepare(sysdictionarysummaryform,actionvalue,orderbyname);
	  editform.action = "SysDictionary.jsp?<%= OvalTools.randomURL() %>&flag=1";
	  editform.target = "_self";
	  isRunning = true;
	  editform.submit();
	}

  function page_mulilang(columnname,label,num,need,entityid,entitycode)
  {
    if(popwindow!=null)
      popwindow.close();
    var strurl="../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=sysdictionarysummaryform&module=IMG&mlctype="+label+"&nativelanguage="+need+"&schema=v_dictionaryforjp&qlname=selectbyvalueandtype&entityid="+entityid+"&entitycode="+entitycode+"&entitytype="+columnname+"&contentid=dictionaryid&colindex="+num;
    var strStatus= "height=250, width=250,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
    popwindow=window.open(strurl, "newwindow",strStatus);
  }

  function valueChange(srcindex, colindex)
  {
    var source = eval("sysdictionarysummaryform.valuebox" + srcindex);
    syncChange(source, "value", colindex, <%=LangNums%>);
  }

  function nameChange()
  {
    var source;
    for (var i = 0; i < <%=LangNums%>; i++)
    {
      var temp = eval("sysdictionarysummaryform.valuename" + i);
      if (temp.value)
      {
        source = temp;
        break;
      }
    }
    syncChange(source, "valuename", 0, <%=LangNums%>);
  }

  function syncChange(source, varname, startindex, syncnum)
  {
    for (var i = 0; i < syncnum; i++)
    {
      var dest = eval("sysdictionarysummaryform." + varname + (startindex + i));
      dest.value = source.value;
    }
  }

  function newvalueChange()
  {
    var source = eval("sysdictionarysummaryform.newvalue");
    source.value = Trim(source.value);
    if (!checkValueDuplication(source.value))
    {
      alert('<%=message.getMessageDesc("VALUE_HAS_EXIST")%>');
      source.value = "";
      return;
    }
    syncChange(source, "value", 0, <%=LangNums%>);
  }

	function checkValueDuplication(value)
	{
	  for (var i = 0; i < sysdictionarysummaryform.nums.value; i++)
	  {
	    var target = eval("sysdictionarysummaryform.valuebox" + (i + 1));
	    if (value == target.value)
	    {
	      return false;
	    }
	  }
	  return true;
	}
	
window.onload = function(){
var varnewtypenameid = document.getElementById("newtypenameid");

varnewtypenameid.onclick = function(){

var value = sysdictionarysummaryform.newtypename.value;
if(this.defaultValue == value){
	varnewtypenameid.value = "";
}else{
	if(value == "" || value == null)
	varnewtypenameid.value = "输入新建字典类型(限字母)";
}

};

var varnewdescriptionid = document.getElementById("newdescriptionid");
varnewdescriptionid.onclick = function(){
var description = sysdictionarysummaryform.newdescription.value;
if(this.defaultValue == description){
	varnewdescriptionid.value = "";
}else{
	if(description == "" || description == null)
	varnewdescriptionid.value = "输入新建字典类型描述";
}

};

};

   function editModeText(obj,index,name,id) {
        if ($(name + index) == null) {
            var c = Trim(obj.innerText);
            var t = new Element('input', {
                'type':'text',
                'value':c,
                'styles':{
                        'width':'150px'
                         },
                'id':name + index,
                'name':name,
                'events':{
                    'blur':function() {
                        saveDataText(this,id,c);
                    },
                    'keydown':function() {
                        if (event.keyCode == 13) {
                            saveDataText(this,id,c);
                        }
                    }
                }
            });
           
            obj.innerHTML = '';
            t.inject(obj);
            selectText(t);
        }
    }
    
    function saveDataText(obj,id,c) {
        var p = obj.parentNode;
        if(Trim(obj.value) == ""){
          // alert("不能为空！");
           p.innerHTML =  "&nbsp;"+c;
           return;
        }
        if(parseFloat(obj.value) == parseFloat(c)){
           p.innerHTML = obj.value;
		   return;
        }
        p.innerHTML = obj.value;
        var req = new Request({
            'url':'<%=contextPath%>/Dispatcher',
            'method':'get',
            'data':'pagename=sysdictionarysummary1&actionname=usave&columnname=' + obj.name + '&columnvalue='+ encodeURI(obj.value) + '&processactionsourceid=' + id
        });
        req.send(); 
    }
     function selectText(obj) {
        var range = obj.createTextRange();
        range.moveStart("character", 0);
        range.select();
    }
    
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form name="sysdictionarysummaryform" method="post" action="<%=contextPath %>/Dispatcher"  target="_parent">
  <input type="hidden" name="pagename" value="sysdictionarysummary1">
  <input type="hidden" name="actionname">
  <input type="hidden" name="nullstring">
   <custom:hidden property="dictionarytype"/>
  <input type="hidden" name="orgcode" value="<%=JspHelper.filterNull(CurUserInfo.get("orgcode"))%>">
  <custom:hidden property="flag"/>
<%@ include file="/inc/PageLocation.inc" %>
<%
    Vector sysdictionarysummary=(Vector)pageContext.getAttribute("sysdictionarysummary");
    if(sysdictionarysummary==null)
    {
        sysdictionarysummary=new Vector();
    }
    Vector alltype=(Vector)pageContext.getAttribute("alltype");
    if(alltype==null)
    {
        alltype=new Vector();
    }
    String strType=(String)pageContext.getAttribute("type");

    if(strType==null)
    {
        strType="";

    }

    cat.debug("strType is :"+strType);
    cat.debug("sysdictionarysummary is:"+sysdictionarysummary);
    cat.debug("alltype is:"+alltype);
%>

<table width="100%" border="0" cellspacing="0">
  <tr>
    <td class="summary_top" colspan="2" ></td>
  </tr>
  <tr>
    <td width=460>
    <table width=100%>
        <tr><td><%=label.getLabelName("L_DicType")+label.getLabelName("L_Colon")%>
          <select name="type" onchange="javascript:page_typechange();">
            <option value="">---</option>
            <logic:iterate id="alltypeitem" collection="<%= alltype %>">
                <%
                    String strSelected="";
                    HashMap hmTemp=(HashMap)pageContext.getAttribute("alltypeitem");
                    if(hmTemp==null)
                    {
                        hmTemp=new HashMap();
                    }
					if(!"1".equals(flag)){
						String oTypeValue=(String)hmTemp.get("dictionarytypecode");
						if(oTypeValue==null)
						{
							oTypeValue="";
						}

						if(oTypeValue.equals(strType))
							strSelected="selected";
                %>
					<option value='<custom:write name="alltypeitem" property="dictionarytypecode"/>' <%=JspHelper.filterNull(strSelected)%>><custom:write name="alltypeitem" property="description"/></option>
				<%}else{
						String oTypeValue=(String)hmTemp.get("type");
						if(oTypeValue==null)
						{
							oTypeValue="";
						}

						if(oTypeValue.equals(strType))
							strSelected="selected";
				%>
					<option value='<custom:write name="alltypeitem" property="type"/>' <%=JspHelper.filterNull(strSelected)%>><custom:write name="alltypeitem" property="description"/></option>
				<%}%>
            </logic:iterate>

          </select>
          </td>
           <td><input type = "text" name="newtypename" size="30" id="newtypenameid" value="输入新建字典类型(限字母)"/></td>
        <td><input type = "text" name="newdescription" size="30" id="newdescriptionid" value="输入新建字典描述"/></td>
         <td><a onclick="add_newdictionarytype();"><custom:button type="1" label="L_Add" imgsrc="add.gif" border="0" style="width:60"/></a></td></tr></table>
      </td>
      <td>
      <table>
	  <%if(!"1".equals(flag)){%>
      <%@ include file="/inc/SummarySearch.inc" %>
	  <%}%>
       </table>
    </td>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        <tr class="deepblue-left" >
          <td width="22" class="title_center">&nbsp;</td>
          <td width="80" class="title_center"><%=label.getLabelName("L_Value")%></td>
          <td class="title_center" width="150"><%=label.getLabelName("L_Desc")%></td>
        </tr>
        <%
            cat.info("Start loop");
            int i=1;
            String strClassType = "";

        %>
        <logic:iterate id="sysdictionarysummaryitem" collection="<%= sysdictionarysummary %>">
        <%
            Integer oColIndexLang=new Integer(i);
            HashMap hmTemp=(HashMap)pageContext.getAttribute("sysdictionarysummaryitem");
            if(hmTemp==null)
            {
                hmTemp=new HashMap();
            }
            String oTypeTemp=(String)hmTemp.get("type");
            if(oTypeTemp==null)
            {
                oTypeTemp="";
            }

            if(oTypeTemp.equals(strType))
            {
                if(i%2 == 1)
                {
                  strClassType = "td-listrom";
                }else{
                  strClassType = "none";
                }
                i++;
        %>
        <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
          <td>
            <input type="checkbox" name="dictionarys" id="dictionarys<%=JspHelper.filterNull(i-1)%>" value="<custom:write name="sysdictionarysummaryitem" property="value"/>" class="normalradio" />
          </td>
			<%if(!"1".equals(flag)){%>
          <td>
         	 <input type="text" name="valuebox" id="valuebox<%=JspHelper.filterNull(i-1)%>" value="<custom:write name="sysdictionarysummaryitem" property="value" />" label="L_Value" command="notnull" onchange="valueChange(<%=JspHelper.filterNull(i-1)%>, <%=(i-1) * LangNums%>);" />
          </td>
          <td>
			<custom:text name="sysdictionarysummaryitem" property="valuename" size="20" command="notnull" module="IMG" label="L_Desc" colIndex="<%=oColIndexLang%>" isFirstMLC="true" multiLangType="valuename" entityId="value" contentId="dictionaryid" needMLC="true" />
          	<a onclick="page_mulilang('valuename','L_Desc','<%=oColIndexLang%>','need','<custom:write name="sysdictionarysummaryitem" property="value" />','<custom:write name="sysdictionarysummaryitem" property="type" />');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
			<%}else{%>	
          <td>
         	 <custom:write name="sysdictionarysummaryitem" property="value" nbsp="true"/>
          </td>
          <td onclick="editModeText(this,'<%=i%>','name','<custom:write name="sysdictionarysummaryitem" property="processactionsourceid"/>');">		
			<custom:write name="sysdictionarysummaryitem" property="valuename" nbsp="true"/>
			<%}%>
          </td>
        </tr>
        <%}%>
        </logic:iterate>
       <input type=hidden name="nums" value="<%=JspHelper.filterNull(sysdictionarysummary.size())%>" />
       <input type=hidden name="numrows" value="<%=LangNums*(JspHelper.filterNull(sysdictionarysummary.size() + 1))%>">
        <%
            cat.info("end loop");
            cat.info("add new ");
            if(i%2 == 1)
            {
              strClassType = "td-listrom";
            }else{
              strClassType = "none";
            }
        %>

        <tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
          <td width="5%">&nbsp; </td>
          <td>
          	<custom:text property="newvalue" size="20" command="notnull,positive" dataType="integer" module="IMG" label="L_Value" onblur="javascript:newvalueChange();" />
            <span class="red"> *</span>
          </td>
          <td>
			<%if(!"1".equals(flag)){%>
           	<custom:text property="valuename" size="20" command="notnull" module="IMG" label="L_Desc" colIndex="0" isFirstMLC="true" multiLangType="valuename" entityId="value" contentId="dictionaryid" needMLC="true" onchange="nameChange();" /><span class="red"> *</span>
          	<a onclick="page_mulilang('valuename','L_Desc','0','need','-1','-1');"><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
			<custom:hidden property="type" value="<%=strType%>" module="IMG" isFirstMLC="false" multiLangType="type" entityId="value" contentId="dictionaryid" needMLC="true" />
			<%}else{%>
           	<custom:text property="newname" size="20" command="notnull" label="L_Desc"/><span class="red"> *</span>		
			<%}%>
          </td>
        </tr>
        <%cat.info("end add new ");%>
        <tr>
          <td colspan="4">
            <%@ include file="/inc/SummaryAction.inc" %>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="summary_top" ></td>
        </tr>
        <tr>
          <td class="td_center">
          <%
          if(strType!=null && !strType.equals(""))
          {
          %>
          <a onclick="page_add();"><custom:button type="1" label="L_Add" imgsrc="add.gif" border="0" style="width:60"/></a>
		  <%if(!"1".equals(flag)){%>
          <a onclick="page_save();"><custom:button type="1" label="L_Save" imgsrc="save.gif" border="0" style="width:60"/></a>
		  <%}%>
          <a onclick="page_delete();"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
          <%}%>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>


